package com.ruoyi.teach.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.teach.domain.TeachCourse;
import com.ruoyi.teach.service.ITeachCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程管理Controller
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Api("课程管理管理")
@RestController
@RequestMapping("/teach/course")
public class TeachCourseController extends BaseController
{
    @Autowired
    private ITeachCourseService teachCourseService;

    /**
     * 查询课程管理列表
     */
    @ApiOperation("查询课程管理列表")   
    @GetMapping("/select")
    public TableDataInfo select(TeachCourse teachCourse)
    {
    	teachCourse.setStatus("1");
        List<TeachCourse> list = teachCourseService.selectTeachCourseList(teachCourse);
        return getDataTable(list);
    }
    

    /**
     * 查询课程管理列表
     */
    @ApiOperation("查询课程管理列表")   
    @PreAuthorize("@ss.hasPermi('teach:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachCourse teachCourse)
    {
        startPage();
        List<TeachCourse> list = teachCourseService.selectTeachCourseList(teachCourse);
        return getDataTable(list);
    }

    /**
     * 导出课程管理列表
     */
    @ApiOperation("导出课程管理列表")    
    @PreAuthorize("@ss.hasPermi('teach:course:export')")
    @Log(title = "课程管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TeachCourse teachCourse)
    {
        List<TeachCourse> list = teachCourseService.selectTeachCourseList(teachCourse);
        ExcelUtil<TeachCourse> util = new ExcelUtil<TeachCourse>(TeachCourse.class);
        return util.exportExcel(list, "course");
    }

    /**
     * 获取课程管理详细信息
     */
    @ApiOperation("获取课程管理详细信息")
    @ApiImplicitParam(name = "id", value = "课程管理ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('teach:course:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(teachCourseService.selectTeachCourseById(id));
    }

    /**
     * 新增课程管理
     */
    @ApiOperation("新增课程管理")
    @PreAuthorize("@ss.hasPermi('teach:course:add')")
    @Log(title = "课程管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachCourse teachCourse)
    {
        return toAjax(teachCourseService.insertTeachCourse(teachCourse));
    }

    /**
     * 修改课程管理
     */
    @ApiOperation("修改课程管理")  
    @PreAuthorize("@ss.hasPermi('teach:course:edit')")
    @Log(title = "课程管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachCourse teachCourse)
    {
        return toAjax(teachCourseService.updateTeachCourse(teachCourse));
    }

    /**
     * 删除课程管理
     */
    @ApiOperation("删除课程管理")
    @ApiImplicitParam(name = "id", value = "课程管理ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('teach:course:remove')")
    @Log(title = "课程管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teachCourseService.deleteTeachCourseByIds(ids));
    }
}
